<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="GRID_PAGE_SIZE" />
<atleap:globalProperty name="${pageScope.GRID_PAGE_SIZE}" defaultValue="10" type="integer" var="pageSize" />

<c:set var="infoCells" value="5" />
<c:set var="constantButtonCells" value="1" />
<c:set var="additionalCells" value="0" />

<atleap:content identifier="information" ignore="true" />
<atleap:grid name="sessionGrid" pageSize="${pageSize}">
    <atleap:queryParameter name="visitorNumber" value="${visitorNumber}" />
    <atleap:messages />
    <table border="0" cellpadding="0" cellspacing="0" class="grid" id="sessionList">
        <thead>
            <tr>
                <th nowrap="nowrap">
                    <atleap:message key="core.statistics.session.form.number" />
                </th>
                <th nowrap="nowrap">
                    <atleap:message key="core.statistics.session.form.numberOfVisits" />
                </th>
                <th nowrap="nowrap">
                    <atleap:message key="core.statistics.session.form.beginDate" />
                </th>
                <th nowrap="nowrap">
                    <atleap:message key="core.statistics.session.form.endDate" />
                </th>
                <th nowrap="nowrap">
                    <atleap:message key="core.statistics.session.form.duration" />
                </th>
                <c:if test="${constantButtonCells + additionalCells > 0}">
                    <th colspan="${constantButtonCells + additionalCells}">
                        <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/spacer.gif" />" border="0"  />
                    </th>
                </c:if>
             </tr>
        </thead>
        <tbody>
            <atleap:contextMenu var="menuId">
                <atleap:rowsIterator beanId="statisticsManager" method="listVisitorSessions" var="session" oddClass="oddRow" evenClass="evenRow">
                    <c:set var="sessionNumber" value="${session.number}" />
                    <c:set var="numberOfVisits" value="${session.numberOfVisits}" />
                    <c:set var="beginDate" value="${session.beginDate}" />
                    <c:set var="endDate" value="${session.endDate}" />
                    <atleap:itemSet>
                        <atleap:rewriteUrl action="core/statistics/visits" var="defaultUrl">
                            <atleap:param name="sessionNumber" value="${sessionNumber}" />
                        </atleap:rewriteUrl>
                        <c:set var="onTrClickCode" value="dispatchGridTrClick(event, this, &#039;${defaultUrl}&#039;);" />
                        <c:set var="tdClass" value="pointerCursorCell" />
                        <tr class="${rowClass}" oncontextmenu="return showContextMenu(${menuId}, event, ${indexId});" onclick="${onTrClickCode}">
                            <td class="${tdClass}" align="center">
                                <c:out value="${sessionNumber}" escapeXml="true" />
                            </td>
                            <td class="${tdClass}" align="center">
                                <c:out value="${numberOfVisits}" escapeXml="true" />
                            </td>
                            <td class="${tdClass}">
                                <atleap:formatDate value="${beginDate}" type="datetime" />
                            </td>
                            <td class="${tdClass}">
                                <atleap:formatDate value="${endDate}" type="datetime" />
                            </td>
                            <td class="${tdClass}">
                                <c:set var="beginInSeconds" value="${(beginDate.time - beginDate.time % 1000) / 1000}" />
                                <c:set var="endInSeconds" value="${(endDate.time - endDate.time % 1000) / 1000}" />
                                <c:set var="totalSeconds" value="${endInSeconds - beginInSeconds}" />
                                <c:set var="hours" value="${(totalSeconds - totalSeconds % 3600) / 3600}" />
                                <c:set var="minutesAndSeconds" value="${totalSeconds % 3600}" />
                                <c:set var="minutes" value="${(minutesAndSeconds - minutesAndSeconds % 60) / 60}" />
                                <c:set var="seconds" value="${minutesAndSeconds mod 60}" />
                                <fmt:formatNumber value="${hours}" minIntegerDigits="2" maxFractionDigits="0" groupingUsed="false" />:<fmt:formatNumber value="${minutes}" minIntegerDigits="2" maxFractionDigits="0" groupingUsed="false" />:<fmt:formatNumber value="${seconds}" minIntegerDigits="2" maxFractionDigits="0" groupingUsed="false" />
                            </td>
                            <atleap:item>
                                <td colspan="${colspan}" width="20" height="20" align="center" valign="middle" class="defaultCursorCell">
                                    <atleap:itemEnabled>
                                        <atleap:message key="core.commons.buttons.view" var="viewMsg"/>
                                        <atleap:itemLink action="core/statistics/visits" title="${viewMsg}">
                                            <atleap:param name="sessionNumber" value="${sessionNumber}" />
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/view.gif" />" border="0" title="${viewMsg}" alt="${viewMsg}" align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${viewMsg}
                                                </atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemEnabled>
                                </td>
                            </atleap:item>
                        </tr>
                    </atleap:itemSet>
                </atleap:rowsIterator>
            </atleap:contextMenu>
            <atleap:noRows>
                <tr>
                    <td class="tfoot" colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                       <em><atleap:message key="core.commons.nothingToShow"/></em>
                    </td>
                </tr>
            </atleap:noRows>
        </tbody>
        <tfoot>
            <tr>
                <atleap:pager pageCount="10">
                    <td colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                        <atleap:message key="core.grid.pager.title" />&nbsp;
                        <atleap:firstPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/first.gif" />" border="0" alt="<atleap:message key="core.grid.pager.first"/>" title="<atleap:message key="core.grid.pager.first"/>" /></atleap:firstPage>
                        <atleap:prevPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/prev.gif" />" border="0" alt="<atleap:message key="core.grid.pager.prev"/>" title="<atleap:message key="core.grid.pager.prev"/>" /></atleap:prevPage>
                        <atleap:pagesIterator>
                            <atleap:page>${pageNumber}&nbsp;</atleap:page>
                            <atleap:currentPage><b>${pageNumber}</b>&nbsp;</atleap:currentPage>
                        </atleap:pagesIterator>
                        <atleap:nextPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/next.gif" />" border="0" alt="<atleap:message key="core.grid.pager.next"/>" title="<atleap:message key="core.grid.pager.next"/>" /></atleap:nextPage>
                        <atleap:lastPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/last.gif" />" border="0" alt="<atleap:message key="core.grid.pager.last"/>" title="<atleap:message key="core.grid.pager.last"/>" /></atleap:lastPage>
                    </td>
                </atleap:pager>
            </tr>
        </tfoot>
    </table>
</atleap:grid>

<atleap:form action="core/statistics/visitors" method="GET" validateOnSubmit="false">
    <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.back" /></atleap:submit>
</atleap:form>
